package com.examlpe.lotterysystem.dao.mapper;

import com.examlpe.lotterysystem.dao.dataobject.ActivityUserDO;
import com.examlpe.lotterysystem.dao.dataobject.UserDO;
import com.examlpe.lotterysystem.service.enums.ActivityUserStatusEnum;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityUserMapper {
    @Insert("<script>" +
            "insert into activity_user(activity_id,user_id,user_name,status)" +
            "values <foreach collection = 'items' item = 'item' index = 'index' separator = ','>"+
            "(#{item.activityId},#{item.userId},#{item.userName},#{item.status})"+
            "</foreach>"+
            "</script>")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    int bachInsert(@Param("items") List<ActivityUserDO> activityUserDOList);
    @Select("select * from activity_user where activity_id = #{id}")
    List<ActivityUserDO> selectUserByActivityId(@Param("id") Long activityId);
    @Select("<script>" +
            "select * from activity_user " +
            "where activity_id = #{activityId} " +
            "and user_id in " +
            "<foreach collection ='userIds' item = 'userIds' open='(' separator =',' close=')'>" +
            "#{userIds}" +
            "</foreach>" +
            "</script>")
    List<ActivityUserDO> bachSelectByAUIds(@Param("activityId") Long activityId,
                                           @Param("userIds") List<Long> userIds);

    @Update("<script>" +
            "update activity_user set status = #{status} " +
            "where activity_id = #{activityId} " +
            "and user_id in " +
            "<foreach collection = 'userIds' item = 'userIds' open='(' separator =',' close = ')'>" +
            "#{userIds}" +
            "</foreach>" +
            "</script>")
    void bachUpdateStatus(@Param("activityId") Long activityId,
                      @Param("userIds") List<Long> userIds,
                      @Param("status") String status);
}
